#ifndef _8B8EFE12_AF07_4C58_9314_0651C195E8D2
#define _8B8EFE12_AF07_4C58_9314_0651C195E8D2

#include "MemJson.h"

namespace x2lib
{

    class MixPool : private MemJson
    {
    public:
        MixPool(const char* pszPwd);
        MixPool(const char* pszPwd, const char* szKey, void* pBin, int nBin);

        bool Pack(const char* pszKey, const char* pszVal);
        bool Pack(const char* pszKey, void* pData, uint32_t nData);
        // 仅返回值 == *pnData != 0 表示解包成功
        uint32_t Unpack(const char* pszKey, void* pData, uint32_t* pnData) const;

        const void* Lock(const char* pszKey, uint32_t* pnData = nullptr);
        void Unlock(const char* pszKey);

        void Clear();

        void* Mem() const;
        uint32_t Len() const;
        uint32_t Cnt() const;
        bool IsValid();
        bool Build(void* pMem, uint32_t nLen);

    private:
        char m_szPwd[32] = { 0 };
        std::set<uint32_t> setLocked;
    };

}

#endif
